package cn.hist.hfp.converter;

import cn.hist.hfp.entity.Reservation;
import cn.hist.hfp.vo.ReservationVO;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Component
public class ReservationConverter {

    private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public ReservationVO convert(Reservation reservation) {
        return ReservationVO.builder().id(reservation.getId()).providerId(reservation.getProvider().getId())
                .reservationDate(formatter.format(reservation.getReservationDate()))
                .providerName(reservation.getProvider().getName())
                .providerNumber(reservation.getProvider().getPhoneNumber()).build();
    }

    public List<ReservationVO> convert(List<Reservation> reservations) {
        List<ReservationVO> reservationVOS = new ArrayList<>();
        for (Reservation reservation: reservations) {
            reservationVOS.add(convert(reservation));
        }
        return reservationVOS;
    }

    public Set<ReservationVO> convert(Set<Reservation> reservations) {
        Set<ReservationVO> reservationVOS = new HashSet<>();
        for (Reservation reservation: reservations) {
            reservationVOS.add(convert(reservation));
        }
        return reservationVOS;
    }
}
